//
//  SimpleTextCell.swift
//  Aiwei
//
//  Created by zhu xietong on 2017/11/1.
//  Copyright © 2017年 zhu xietong. All rights reserved.
//

import Foundation
import Eelay


open class SimpleTextCell: FieldCell {
    public var textV = FTextField()
    override open func addLayoutRules() {
        super.addLayoutRules()
//        let w = Int(FieldCell.name_width) + 20
        contentView.eelay = [
            [titleL,FieldCell.name_width.+1000],
            [textV,[ee.T.B,[8,-8]],[titleL,ee.R,ee.L,8],[rightIcon,ee.L,ee.R,-8]],
        ]
        _ = titleL.ui.bfont12.left
        textV.valueT.textAlignment = .left
        
    }
    
    open override func mo_model_reload() {
        textV.controller = self.content_controller
        titleL.text = mo.model["title",""]
//        contentView.fillData(model: mo.model)
        
        if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.field)", mo.model)
        {
            textV.mo.model = f
        }
        else
        {
            if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.fields).0", mo.model)
            {
                textV.mo.model = f
            }
        }
    }
    
}



open class SimpleTextCell1: FieldCell {
    public let textV = FTextField()
    open override func addLayoutRules() {
        super.addLayoutRules()
        
        

        //        let w = Int(FieldCell.name_width) + 20
        contentView.eelay = [
            [textV,[ee.T.B,[0,0]],[ee.L,AppTheme.edge],[rightIcon,ee.L,ee.R,-8]],
        ]
        titleL.alpha = 0
        textV.valueT.textAlignment = .left
    }
    
    open override func mo_model_reload() {
        self.titleL.text = mo.model["title",""]

        textV.controller = self.content_controller
//        contentView.fillData(model: mo.model)
        
        if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.field)", mo.model)
        {
            textV.mo.model = f
        }
        else
        {
            if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.fields).0", mo.model)
            {
                textV.mo.model = f
            }
        }
    }
    
}



open class PasswordTextCell: SimpleTextCell1 {
    
    open override func mo_model_reload() {
        super.mo_model_reload()
        textV.valueT.keyboardType = .asciiCapable
        if #available(iOS 11.0, *) {
            textV.valueT.textContentType = .password
            if #available(iOS 12.0, *) {
                textV.valueT.passwordRules = nil
            } else {
                // Fallback on earlier versions
            }
        } else {
            // Fallback on earlier versions
        }
        textV.valueT.isSecureTextEntry = true
    }
    
}
